import { app, ipcMain, globalShortcut, BrowserWindow } from "electron";
import { winparams } from "./params";
import { WINDOW_PORT, RENDER_HTML_PATH } from "@/settings";
import {
    setWindowById,
    createMainWindow,
    getMainWindow,
} from "@/jc-electron-tools/windows";
import { createTrayIcon } from "../../utils/tray";
import { getLogger } from "@/utils";
// import devtools from '@vue/devtools'

const logger = getLogger();

function newWinMain() {
    createMainWindow(winparams);
    const window = getMainWindow();

    // 用于主进程获取主窗口的 id
    ipcMain.on('get-main-window', (event) => {
        event.reply('main-window', window.id);
    });

    if (process.env.NODE_ENV === "development") {
        window.loadURL(`http://127.0.0.1:${WINDOW_PORT.desktop}/`);
        logger.gradient(
            `Start Main Window At URL: http://localhost:${WINDOW_PORT.desktop}/`
        );
        // devtools.connect('http://192.168.1.118')
    } else {
        window.loadFile(`${RENDER_HTML_PATH.desktop}`);
    }
    // 托盘图标
    createTrayIcon();
    return window.id;
}

export { newWinMain };
